﻿#region imports

using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using System.Text;

using CondeNet.AssetManager.Data;
using CondeNet.AssetManager.Business;
using CondeNet.AssetManager.Business.Interface;

#endregion

namespace CondeNet.AssetManager.DataProvider.Sql.Mappers
{
    public static class AssetRightsUsageMapper
    {
        internal static IAssetRightsUsage ToBusinessObject ( T_AssetRightsUsage entity )
        {
            IAssetRightsUsage obj = new AssetRightsUsage (
                entity.AssetRightsUsage_IDPK ,
                entity.StatusID_FK ,
                entity.StartPublishDate_DT.Value ,
                entity.EndPublishDate_DT.Value ,
                entity.Group_NVC ,
                entity.AssetID_FK.Value );

            // parent is causing infinite recursion: obj.Asset = AssetMapper.ToBusinessObject ( entity.T_Asset );
            if ( entity.T_Status != null ) obj.Status = StatusMapper.ToBusinessObject ( entity.T_Status );

            return obj;
        }

        internal static T_AssetRightsUsage ToEntity ( IAssetRightsUsage v )
        {
            T_AssetRightsUsage entity = new T_AssetRightsUsage ( );

            entity.AssetRightsUsage_IDPK = v.ID;
            entity.StatusID_FK = v.StatusID;
            entity.StartPublishDate_DT = v.StartPublishDate;
            entity.EndPublishDate_DT = v.EndPublishDate;
            entity.Group_NVC = v.Group;
            entity.AssetID_FK = v.AssetID;

            // parent is causing infinite recursion: entity.T_Asset = AssetMapper.ToEntity ( v.Asset );
            if ( v.Status != null ) entity.T_Status = StatusMapper.ToEntity ( v.Status );

            return entity;
        }

        internal static IList<IAssetRightsUsage> ToBusinessObjects ( IList<T_AssetRightsUsage> dalList )
        {
            return dalList.Select ( tmp => ToBusinessObject ( tmp ) ).ToList ( );
        }

        internal static IList<T_AssetRightsUsage> ToEntities ( IList<IAssetRightsUsage> entityList )
        {
            EntitySet<T_AssetRightsUsage> list = new EntitySet<T_AssetRightsUsage>(); 
            entityList.Select ( tmp => ToEntity ( tmp ) ).ToList ( ).ForEach(list.Add);
            return list;
        }
    }
}
